import React, { useState, useEffect } from 'react'
import "./Coupon.less"
import Cate from "./Cate/Cate"
import Header from "../../components/Header"
import { reqGetcoupon, reqGetindexgoods } from "../../http/api"
export default function Coupon() {
    //初始化数据 
    const [goods, setGoods] = useState([]);
    const [n, setN] = useState(0);

     // 3.2. 请求商品数据
     useEffect(() => {
        reqGetcoupon().then((res) => {
        if (res.data.code === 200) {
          setGoods(res.data.list);
        }
      });
    }, []);
   
    return (
        <div className="coupon">
            <Header title="优惠券" back></Header>
            {/* 3.3 分类 */}
        {goods.length > 0 ? (
        <Cate showList={goods[n].content} n={n} setN={(e) => setN(e)}></Cate>
      ) : null}
        </div>
    )
}
